"use strict";
angular.module('app.granaryInfo').controller('InventoryLogCtrl', function($q,$scope,$http,HTTPDataService,Auths){

   /*if(!Auths.getUser())
    {
         window.location.href=baseurls+"#/login";
    }*/ 
     if(Auths.getUser())
    {
        var $user = Auths.getUser();
        var  username=  $user.name;
        if($user.rolename == 'admin')
          $scope.showInventory = true;
        else
          $scope.showInventory = false;
       
    } 
    
    HTTPDataService.getGranaryAll_v().then(function(response) {
          //console.log(response['content']);
           $scope.granaryInfo = response;
          
     });
   
     //配置分页基本参数
        $scope.paginationConf = {
            currentPage: 1,
            itemsPerPage: 10,
            pagesLength: 5,
            totalItems:20,
            perPageOptions: [10, 20, 30, 40, 50],
            onChange: function(){
            }
        };
        
     $scope.queryCondition = {
                 granaryNum:'',
                 dateS:'',
                 dateE:'',
                 pageIndex: $scope.paginationConf.currentPage,
                 pageSize: $scope.paginationConf.itemsPerPage
               };
     $scope.queryCondition.granaryNum = "选择粮仓";

     $scope.changeGranary = function(number){
   
        $scope.queryCondition.granaryNum = number;
        GetAllEmployee();
      };

     
     $scope.conQuery = function(){
        
         if(!$scope.queryCondition.dateS || !$scope.queryCondition.dateE ){
             
            $.smallBox({
                        title : "警告: <strong>" + ' " ' + "请选择开始日期和结束日期" + ' " ' + "</strong> ",
                        content : "请选择要查询的日期和粮仓，再提交",
                        color : "#FF8C00",
                        timeout : 5000,
                        icon : "fa fa-warning"
                    });

           }
         else if($scope.queryCondition.granaryNum == "选择粮仓"){

               $.smallBox({
                        title : "警告: <strong>" + ' " ' + "请选择粮仓" + ' " ' + "</strong> ",
                        content : "请选择要查询的日期和粮仓，再提交",
                        color : "#FF8C00",
                        timeout : 5000,
                        icon : "fa fa-warning"
                    });
             } 
         else
           {

                GetAllEmployee(); 
           }            
  
        };
      
      var GetAllEmployee = function () {
 
            $scope.queryCondition.pageIndex = $scope.paginationConf.currentPage;
            $scope.queryCondition.pageSize  = $scope.paginationConf.itemsPerPage;
             HTTPDataService.getInventoryLog($scope.queryCondition).then(function (response) {
              
                $scope.paginationConf.totalItems = response['sum'];
                $scope.inventoryLog = response['content'];
               
            });
 
        }
 
        /***************************************************************
        当页码和页面记录数发生变化时监控后台查询
        如果把currentPage和itemsPerPage分开监控的话则会触发两次后台事件。
        ***************************************************************/
        $scope.$watch('paginationConf.currentPage + paginationConf.itemsPerPage', GetAllEmployee);

     /* $scope.paginationConf = {
            currentPage: 1,
            totalItems: 8000,
            itemsPerPage: 15,
            pagesLength: 15,
            perPageOptions: [10, 20, 30, 40, 50],
            onChange: function(){
            }
        };*/
  
});